const Router = require("koa-router");
const router = new Router();
const login = require("./login");
const register = require("./register");
const userInfo = require("./userInfo");
const upload = require("./upload");
const article = require("./article");
const namelist = require("./namelist");
const { query } = require("../../utils");

// router.get("/", async (ctx) => {
//   let data = await new Promise((resolve, reject) => {
//     // 写一句sql语句
//     var sql = `SELECT id,username FROM user`;
//     query(sql, (err, data) => {
//       if (err) reject(err);
//       resolve(data); // 返回拿到的数据
//     });
//   });
//   ctx.body = data; // 将查询结果返回到页面中
// });

router.get("/", async (ctx) => {
  ctx.body = "管理系统";
});

router.use("/login", login.routes(), login.allowedMethods());
router.use("/register", register.routes(), register.allowedMethods());
router.use("/userInfo", userInfo.routes(), userInfo.allowedMethods());
router.use("/upload", upload.routes(), upload.allowedMethods());
router.use("/article", article.routes(), article.allowedMethods());
router.use("/namelist", namelist.routes(), namelist.allowedMethods());

module.exports = router;
